package com.zj.java21demo.controller;

import com.zj.java21demo.dto.req.LoginDto;
import com.zj.java21demo.service.TUserService;
import com.zj.java21demo.utils.ResultVoUtil;
import com.zj.java21demo.vo.ResultVo;
import io.micrometer.common.util.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 登录类
 * @Version 1.0.0
 * @Date 2024/2/28 10:16
 * @Created by zhangjun
 */
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    TUserService tUserService;

    @PostMapping("login")
    public ResultVo login(@RequestBody LoginDto loginDto) {
        String account = loginDto.getAccount();
        String password = loginDto.getPassword();

        if(StringUtils.isBlank(account)) {
            return ResultVoUtil.error(400, "账号不能为空");
        }
        if(StringUtils.isBlank(password)) {
            return ResultVoUtil.error(400, "密码不能为空");
        }

        return tUserService.loginAndGenerateToken(loginDto);
    }
}
